<template>
  <div class="mainor">
    <div class="mainsu">
      <div class="main_spac1">
        <div class="main_white padding10 paddingBottom20">
          <div class="main_crumbs boxdq">
            <div class="main_crumbs_l">
              <a href="javascript:;" @click="$router.back(-1)">
                <i class="el-icon-arrow-down"></i>返回
              </a>
              <em>|</em>
              <span>首页</span>
            </div>
          </div>
          <div class="mainor_form marginTop15">
            <div class="mainor_te">
              <el-button @click="get_allRead">全部标为已读</el-button>
            </div>
            <el-form
              :inline="true"
              :model="form"
              class="demo-form-inline"
              ref="userListFrom"
              label-width="0"
            >
              <el-form-item label=" " prop="content">
                <el-input
                  placeholder="请输入内容"
                  prefix-icon="el-icon-search"
                  v-model="form.content"
                >
                </el-input>
              </el-form-item>

              <el-form-item>
                <el-button
                  class="reset marginLeft10"
                  type="primary"
                  @click="reset"
                  >重置</el-button
                >
                <el-button
                  type="primary"
                  @click="getArticleList"
                  :loading="loading"
                  >搜索</el-button
                >
              </el-form-item>
            </el-form>
          </div>

          <div class="main_table marginTop10" style="min-height: 550px">
            <el-table
              ref="multipleTable"
              v-loading="loading"
              :data="list.data"
              element-loading-text="加载中"
              fit
              border
              highlight-current-row
              :header-cell-class-name="this.$verticaline"
            >
              <el-table-column align="center" label="" prop="" width="50">
                <template slot-scope="scope"
                  ><div class="dot-box">
                    <span class="dot" v-if="scope.row.unread == 0"></span></div
                ></template>
              </el-table-column>

              <el-table-column label="用户名称" prop="" width="200">
                <template slot-scope="scope"
                  ><span>
                    {{ scope.row.member.nickname }}
                  </span></template
                >
              </el-table-column>
              <el-table-column label="图片" prop="" width="300">
                <template slot-scope="scope"
                  ><div>
                    <el-image
                      v-for="(item, index) in scope.row.newimg"
                      :key="index"
                      :src="item"
                      :preview-src-list="scope.row.newimg"
                    >
                      <div slot="error" class="image-slot">
                        <img :src="puzzleImg" />
                      </div>
                    </el-image></div
                ></template>
              </el-table-column>
              <el-table-column
                align="center"
                show-overflow-tooltip
                label="内容"
                prop="content"
              >
                <template slot-scope="scope"
                  ><span>
                    {{ scope.row.content }}
                  </span></template
                >
              </el-table-column>
              <el-table-column label="提交时间" prop="" width="200">
                <template slot-scope="scope"
                  ><span>
                    {{
                      scope.row.created_at
                        ? parseTime(scope.row.created_at)
                        : ""
                    }}
                  </span></template
                >
              </el-table-column>
              <el-table-column
                label="管理操作"
                align="left"
                fixed="right"
                width="200"
                class-name="main_hei"
              >
                <template slot-scope="scope">
                  <el-link
                    v-if="scope.row.unread != 1"
                    type="danger"
                    @click="unread(scope)"
                    >标记为已读</el-link
                  >
                  <el-link v-else type="success" disabled>已读</el-link>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="main_page boxdq">
            <div></div>
            <!-- 分页 -->
            <div class="main_page_r">
              <el-pagination
                :current-page="current.page"
                :page-sizes="[50, 100, 200]"
                :page-size="limit"
                layout="total, sizes, prev, pager, next, jumper"
                :total="totalCount"
                background
                @size-change="changeLimit"
                @current-change="changePage"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";

import { get_feedback_MoreList, unread, get_allRead } from "@/api/index/index";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { puzzleImg } from "@/api/currency";
import { parseTime } from "@/utils/index";


export default {
  computed: {
    ...mapGetters(["avatar"]),
  },
  data() {
    return {
      parseTime,
      input4: "",
      puzzleImg,
      // 分页
      current: {
        page: 1,
        per_page: 50,
      },
      limit: 50,
      totalCount: 1,
      loading: false,
      form: {
        content: "",
      },
      // 列表数据
      list: {
        total: "",
        data: [],
      },
    };
  },
  mounted() {},
  created() {
    // 列表
    this.get_feedback_MoreList();
  },
  methods: {
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.get_feedback_MoreList();
    },
    // 重置
    reset() {
      this.$refs["userListFrom"].resetFields();
      this.get_feedback_MoreList();
    },

    // 分页
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.get_feedback_MoreList();
    },
    changePage(page) {
      this.current.page = page;
      this.get_feedback_MoreList();
    },
    // 列表
    get_feedback_MoreList() {
      this.loading = true;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.form,
        this.current
      );
      get_feedback_MoreList(data).then((res) => {
        if (res.errcode == 0) {
          res.data.list.data.map((e) => {
            e.newimg = [];
            e.img.map((a) => {
              let imgpath = this.avatar.domain + a.img;
              e.newimg.push(imgpath);
            });
          });
          this.loading = false;
          this.list = res.data.list;
          this.totalCount = res.data.list.total;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 标为已读
    unread(scope) {
      let id = scope.row.id;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: id }
      );
      unread(data).then((res) => {
        if (res.errcode == 0) {
          this.$message.success("标记成功");
          scope.row.unread = 1;
        }
      });
    },
    // 全部标为已读
    get_allRead() {
      this.$confirm("是否将全部反馈标为已读?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let data = Object.assign(
          {
            sign: Md5(
              objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
            ),
          },
          apiUrl().name
        );
        get_allRead(data).then((res) => {
          if (res.errcode == 0) {
            this.get_feedback_MoreList();
          }
        });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.back {
  display: inline-block;
  padding-top: 8px;
  font-size: 14px;
  color: #606266;
  cursor: pointer;
  &:hover {
    color: #03a98e;
  }
}
.dot-box {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.dot {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: red;
}
.el-image {
  width: 80px;
  margin-right: 20px;
}
.main_table /deep/.el-table--small td .cell {
  min-height: 45px;
  height: auto;
  display: flex;
  align-items: center;
}
.main_table /deep/.el-table--small td {
  &:nth-child(4) {
    .cell {
      justify-content: center;
    }
  }
}
// 支付状态
.success {
  color: $order_color3;
}
.unpaid {
  color: $colour_red;
}
// 订单状态
.order1 {
  color: $order_color1;
}
.order2 {
  color: $order_color2;
}
.order3 {
  color: $order_color3;
}
.order4 {
  color: $order_color4;
}
</style>
